import time

from pathlib import Path


def list_files_with_pathlib(folder_path):
    try:
        folder = Path(folder_path)
        if not folder.exists():
            print(f"错误：目录 '{folder_path}' 不存在。")
            return []
        if not folder.is_dir():
            print(f"错误：'{folder_path}' 不是一个目录。")
            return []

        # 获取所有文件（不包括子目录）
        files = [file.name for file in folder.iterdir() if file.is_file()]
        return files
    except PermissionError:
        print(f"错误：没有权限访问目录 '{folder_path}'。")
        return []


def get_subfolders(path):
    p = Path(path)
    # 只获取第一层子文件夹
    return [f for f in p.iterdir() if f.is_dir()]


if __name__ == '__main__':
    print('开始')
    timestamp = int(time.time())
    folder_path = "C:\\2\\"
    folders = get_subfolders(folder_path)
    for f in folders:
        print(f)
        folder_path = str(f).replace('\\2\\', '\\1\\')
        files = list_files_with_pathlib(folder_path)
        folder_path = str(f)
        files_2 = list_files_with_pathlib(folder_path)
        for file_1 in files:
            found = True
            for file_2 in files_2:
                if file_2[0:-8] == file_1[0:-4]:
                    found = False
                    break
            if found:
                print(file_1)
    endTime = int(time.time())
    print(str(endTime - timestamp))
    print('结束')
